#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e4 + 5;

int n, m;
int tr[N * 25][26], ed[N * 25], num;
void insert(string s) {
  int p = 0;
  for (char c : s) {
    int ch = c - 'a';
    if (!tr[p][ch]) tr[p][ch] = ++num;
    p = tr[p][ch];
  }
  ed[p] = 1;
}
set<int> ans;
void search(int p, string& s, int pos) {
  if (pos == s.size() && ed[p]) ans.insert(p);
  char c = s[pos];
  if (c == '*') {
    int res = 0;
    rep(i, 0, 25) if (tr[p][i]) search(tr[p][i], s, pos + 1);
  } else {
    int ch = c - 'a';
    if (!tr[p][ch]) return;
    search(tr[p][ch], s, pos + 1);
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) {
    string s;
    cin >> s;
    insert(s);
  }
  while (m--) {
    string s;
    cin >> s;
    ans.clear();
    search(0, s, 0);
    if (ans.size()) {
      cout << -1 << endl;
      continue;
    }
    rep(i, 0, s.size() - 1) {  // modify
      string t = s;
      t[i] = '*';
      search(0, t, 0);
    }
    rep(i, 0, s.size() - 1) {  // del
      string t = s.substr(0, i) + s.substr(i + 1);
      search(0, t, 0);
    }
    rep(i, 0, s.size()) {  // add
      string left = s.substr(0, i);
      string right = s.substr(i);
      string t = left + '*' + right;
      search(0, t, 0);
    }
    cout << ans.size() << endl;
  }
  return 0;
}